package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PublishDeviceGroup 投放设备分组表
type PublishDeviceGroup struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	Name      string `json:"name" gorm:"column:name;type:string;size:50;not null;default:'';comment:分组名称"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	UpdatedAt int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;not null;default:0;index:updated_at;comment:更新时间"`
	DeletedAt int64  `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;not null;default:0;comment:删除时间"`
	Type      int64  `json:"type" gorm:"column:type;type:int;size:8;not null;default:0;comment:组类型"`
}

// TableName 表名
func (PublishDeviceGroup) TableName() string {
	return "publish_device_group"
}

// BeforeCreate 自增id
func (l *PublishDeviceGroup) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PublishDeviceGroup{})
}
